package com.tomshushu.doc.freedoc.modular.doc.controller;

import com.tomshushu.doc.freedoc.core.model.response.ResponseData;
import com.tomshushu.doc.freedoc.core.model.response.SuccessResponseData;
import com.tomshushu.doc.freedoc.modular.directory.model.param.AddDirectoryParam;
import com.tomshushu.doc.freedoc.modular.directory.model.param.ReNameParam;
import com.tomshushu.doc.freedoc.modular.directory.service.DirectoryService;
import com.tomshushu.doc.freedoc.modular.doc.model.param.*;
import com.tomshushu.doc.freedoc.modular.doc.service.DocService;
import jakarta.annotation.Resource;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * @description:
 * @author: zhouhong
 * @date: 2025-06-10 17:16
 * @version: 1.0
 */
@RestController
@RequestMapping("/doc")
public class DocController {
    @Resource
    private DocService docService;

    /**
     * 添加文档
     *
     * @param param
     * @return
     */
    @PostMapping("/addDoc")
    public ResponseData addDoc(@RequestBody AddDocParam param) {
        return new SuccessResponseData(docService.addDoc(param));
    }

    @PostMapping("/editDoc")
    public ResponseData editDoc(@RequestBody EditDocParam param) {
        docService.editDoc(param);
        return new SuccessResponseData();
    }

    @PostMapping("/renameDoc")
    public ResponseData renameDoc(@RequestBody RenameParam param) {
        docService.renameDoc(param);
        return new SuccessResponseData();
    }

    /**
     * 获取文档
     *
     * @param param
     * @return
     */
    @PostMapping("/getDocByDocId")
    public ResponseData getDocByDocId(@RequestBody DeleteDocParam param) {
        return new SuccessResponseData(docService.getById(param));
    }
    /**
     * 删除文档
     *
     * @param param
     * @return
     */
    @PostMapping("/deleteDoc")
    public ResponseData deleteDoc(@RequestBody DeleteDocParam param) {
        docService.deleteDoc(param);
        return new SuccessResponseData();
    }

    /**
     * 获取目录以及子目录下所有文档
     *
     * @param param
     * @return
     */
    @PostMapping("/listAllChildDirectoryDoc")
    public ResponseData listAllChildDoc(@RequestBody ListDocParam param) {
        param.setIsAll(true);
        return new SuccessResponseData(docService.listAllChildDoc(param));
    }

    /**
     * 仅仅获取当前目录下文档（不包含子目录）
     *
     * @param param
     * @return
     */
    @PostMapping("/listChildDirectoryDoc")
    public ResponseData listChildDirectoryDoc(@RequestBody ListDocParam param) {
        param.setIsAll(false);
        return new SuccessResponseData(docService.listAllChildDoc(param));
    }
    /**
     * 获取目录以及子目录下所有文档
     *
     * @param param
     * @return
     */
    @PostMapping("/listAllProjectDoc")
    public ResponseData listAllProjectDoc(@RequestBody ListDocParam param) {
        param.setDirectoryId(null);
        return new SuccessResponseData(docService.listAllChildDoc(param));
    }


    /**
     * 搜索项目下所有文档
     *
     * @param param
     * @return
     */
    @PostMapping("/listSearch20Doc")
    public ResponseData listSearch20Doc(@RequestBody SearchDocParam param) {
        return new SuccessResponseData(docService.listSearch20Doc(param));
    }


}